package br.com.iswe.teste.spring;

import java.util.ResourceBundle;

import junit.framework.TestCase;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import br.com.iswe.core.exp.ISWEConfigurationException;

public class SpringTestCase extends TestCase{
	protected final Log log = LogFactory.getLog(getClass());

	protected ResourceBundle rb;
	
	protected static ApplicationContext ctx = null;
	
	public SpringTestCase(){
		super();
	}
	
	public SpringTestCase(String metodoTest){
		super(metodoTest);
	}
	 
    public static ApplicationContext getApplicationContext(String[] paths){
        if(ctx == null){
        	try{
        		ctx = new ClassPathXmlApplicationContext(paths);
        	}
        	catch(Exception exp){
        		exp.printStackTrace();
        		throw new RuntimeException("Erro Criando BeanFactory do Spring", exp);
        	}
        }
        return ctx;
    }
    
    public static ApplicationContext getApplicationContext(){
        if(ctx == null){
            throw new ISWEConfigurationException("Application Context nao configurado.");
        }
        return ctx;
    }
    
	// This static block ensures that Spring's BeanFactory is only loaded
    // once for all tests
    static {        
        //String[] paths = {"classpath*:/*/*Context.xml",
        //				  "classpath*:/*/*Objects.xml",
        //                 "classpath*:/*/*Override.xml",
        //                  "classpath*:/test-*.xml"};
        //ctx = new ClassPathXmlApplicationContext(paths);
    }

    private static boolean dataLoaded = false;
    
	protected void setUp() throws Exception {
		super.setUp();
		if(!dataLoaded){
			loadDataOnce();
			dataLoaded = true;
		}
	}
	
	protected void tearDown() throws Exception {
		super.tearDown();
	}
	
	protected void loadDataOnce(){
		
		
	}
	
}
